<div class="container-fluid">
    <div class="block-header">
        <h2>工具 > 公告</h2>
    </div>
    <!-- Vertical Layout -->
    <div class="row">
        <div class="col-lg-6 col-md-6">
            <div class="card">
                <div class="header">
                    <h2>管理公告</h2>
                </div>
                <div class="body">
                    <div class="alert alert-success announcement-settings-alert"></div>
                    <form class="announcement-settings" method="POST">
                    	<div class="form-group form-float">
                            <div class="form-line">
                                <textarea name="announcement_text" id="announcement_text" class="form-control" cols="30" rows="10"></textarea>
                                <label class="form-label">创建新公告 (支持HTML)</label>
                            </div>
                        </div>
                        <input type="hidden" name="hash_id" value="<?php echo Wo_CreateSession();?>">
                        <button type="submit" class="btn btn-primary m-t-15 waves-effect">创建</button>
                    </form>
                    <div class="page-margin">
			            <hr>
			            <h5>活跃公告</h5>
			            <div class="active-announcements announcements">
			               <?php
			                  $activeAnnouncements = Wo_GetActiveAnnouncements();
			                  
			                  if (count($activeAnnouncements) < 1) {
			                    
			                    echo '<h5 class="no-active-announcements"><small>没有有效的公告.</small></h5>';
			                  } else {
			                  foreach ($activeAnnouncements as $wo['activeAnnouncement']) {
			                  
			                     echo Wo_LoadAdminPage('manage-announcements/active-list');
			                     
			                  }
			                  }
			                  ?>
			            </div>
			         </div>
			         <div class="page-margin">
			            <hr>
			            <h5>不活跃公告</h5>
			            <div class="inactive-announcements announcements">
			               <?php 
			                  $inactiveAnnouncements = Wo_GetInactiveAnnouncements();
			                  
			                   if (count($inactiveAnnouncements) < 1) {
			                    
			                    echo '<h5 class="no-inactive-announcements"><small>没有不活跃公告.</small></h5>';
			                  } else {
			                  foreach ($inactiveAnnouncements as $wo['inactiveAnnouncement']) {
			                  
			                     echo Wo_LoadAdminPage('manage-announcements/inactive-list');
			                     
			                  } 
			                  }
			                  ?>
			            </div>
			         </div>
                </div>
            </div>
        </div>
        <div class="clearfix"></div>
    </div>
    <!-- #END# Vertical Layout -->
<script>
$(function() {
    var form_announcement_settings = $('form.announcement-settings');
    form_announcement_settings.ajaxForm({
        url: Wo_Ajax_Requests_File() + '?f=admin_setting&s=add_new_announcement',
        beforeSend: function() {
            form_announcement_settings.find('.waves-effect').text('Please wait..');
        },
        beforeSubmit : function(arr, $form, options){
          arr.splice(0, 1);
          arr.push({name:'announcement_text', value:btoa(unescape(encodeURIComponent($('#announcement_text').val())))})
        },
        success: function(data) {
        	if (data.status == 200) {
	            $('.no-active-announcements').hide(100);
	            $('.active-announcements').prepend(data.text);
	            form_announcement_settings.find('.waves-effect').text('Create');
	        }
        }
    });
});

function Wo_DeleteAnnouncement(id) {
   var announcement_container = $('.announcements').find('.announcement-' + id);
   $.get(Wo_Ajax_Requests_File(), {
      f: 'admin_setting',
      s: 'delete_announcement',
      id: id
   }, function (data) {
      if (data.status == 200) {
         announcement_container.slideUp(200, function () {
            $(this).remove();
         });
      }
   });
}

function Wo_DisableAnnouncement(id) {
   var announcement_container = $('.active-announcements').find('.announcement-' + id);
   var inactiveannouncement_container = $('.inactive-announcements');
   $.get(Wo_Ajax_Requests_File(), {
      f: 'admin_setting',
      s: 'disable_announcement',
      id: id
   }, function (data) {
      if (data.status == 200) {
         announcement_container.slideUp(200, function () {
            $(this).remove();
         });
         if (data.html.length != 0) {
            $('.no-inactive-announcements').hide(100);
            inactiveannouncement_container.prepend(data.html);
         }
      }
   });
}

function Wo_ActivateAnnouncement(id) {
   var announcement_container = $('.inactive-announcements').find('.announcement-' + id);
   var activeannouncement_container = $('.active-announcements');
   $.get(Wo_Ajax_Requests_File(), {
      f: 'admin_setting',
      s: 'activate_announcement',
      id: id
   }, function (data) {
      if (data.status == 200) {
         announcement_container.slideUp(200, function () {
            $(this).remove();
         });
         if (data.html.length != 0) {
            activeannouncement_container.prepend(data.html);
         }
      }
   });
}
</script>